<template>
  <div class="test-paper-increase">
      <!-- 新增弹窗 -->
      <a-modal
       class="test-paper-modal"
       :visible="visibleShow"
       :title="addEditParameter.id?'编辑':'新增'"
       @ok="visibleShow = false"
       :maskClosable="false"
       cancelText=""
       :centered="true"
       :closable="false"
       width="100%"
       wrapClassName="full-modal"
       >
       <a-spin
          :spinning="spinning"
          class="spin"
          style="background-color: rgb(240, 242, 245)">
          <div style="margin-bottom: 20px;">
              <a-button class="blue-btn" type="primary" @click="returnClick()">返回</a-button>
              <a-button style="margin-left: 10px;" class="blue-btn" type="primary" @click="refreshClick()">刷新</a-button>
              <a-button style="margin-left: 15px;" :loading="!visibleShow || confirmLoading" class="blue-btn" type="primary" @click="saveMainTable">保存</a-button>
          </div>
            <div class="massage" style="background-color: rgb(240, 242, 245)" :key="infoKey">
              <a-collapse default-active-key="1" :bordered="false">
                <template #expandIcon="props">
                  <a-icon type="double-right" :rotate="props.isActive ? 90 : 0" />
                </template>
                <a-collapse-panel key="1" header="培训基本信息" :style="customStyle">
                  <div class="form">
                    <everdayFormNoRowAntcol
                      :key="inspectorKey"
                      :formItem="trainingForItem"
                      :beforeCreate="everdayform"
                      :labelcol="{ span: 8 }"
                    >
                    </everdayFormNoRowAntcol>
                  </div>
                </a-collapse-panel>
                <a-collapse-panel v-if="collapseShow" key="2" header="选择培训考试试卷" :style="customStyle" class="collapse-panel-head-l255">
                  <a-button class="blue-btn" type="primary" @click="showModal"> 选择试卷</a-button>
                  <div style="margin-top: 15px;">
                      <compTable
                          :key="pxsjxxListKey"
                          :config="dataTableConfig"
                          :columns="columns"
                          :scroll="{ x: 200 }"
                          :requestParamObj="pxSjRequestParams"
                          @sorterChange="sorterChange"
                          >
                              <template v-slot:operation="{record}" data-desc="培训试卷操作栏">
                                  <a-form layout="inline" class="search-form">
                                      <a-form-item >
                                          <a-button class="red-btn" type="primary" @click="removeSj(record)">移除</a-button>
                                      </a-form-item>
                                  </a-form>
                              </template>
                        </compTable>
                  </div>
                  <a-modal
                    title="试卷信息"
                    :footer="null"
                    :width="modalWidth"
                    :visible="visible"
                    :confirm-loading="confirmLoading"
                    @ok="submit"
                    @cancel="handleCancel"
                  >
                    <div>
                      <compSearchCriteria
                        :formItem.sync="formItem"
                        @searchHandleChange="searchHandleChange"
                        v-model="dataTableConfig.requestParams"
                        ref="refSearchCriteria"
                        />
                      <compTable
                          :key="compSelectorkey"
                          :config='dataTableConfig'
                          :columns="columns"
                          :scroll="{ x: 200 }"
                          :requestParamObj="requestParams"
                          @sorterChange="sorterChange"
                          >
                              <template v-slot:operation="{record}" data-desc="自定操作栏">
                                  <a-form layout="inline" class="search-form">
                                      <a-form-item >
                                          <a-button class="blue-btn" type="primary" @click="reviseClick(record)">选择试卷</a-button>
                                      </a-form-item>
                                  </a-form>
                              </template>
                          </compTable>
                    </div>
                  </a-modal>
                </a-collapse-panel>
                <a-collapse-panel v-if="collapseShow" key="3" header="选择参与培训人员" :style="customStyle" class="collapse-panel-head-l255">
                  <a-button class="blue-btn bth-mar-right" type="primary" @click="selectRecipientClick"> 选择参与培训人员</a-button>
                  <!-- <a-button class="blue-btn bth-mar-right" type="primary" @click="sendTestPapers"> 给参加培训的人员发送试卷</a-button> -->
                  <a-button class="blue-btn" type="primary" @click="sendSms"> 给参加培训的人员-发送试卷短信</a-button>
                  <div>
                    <a-form layout="inline" style="display: flex;justify-content: flex-end;">
                      <a-form-item>
                          <a-button class="blue-btn" type="primary" @click="downTemplate" >下载模板</a-button>
                      </a-form-item>
                      <a-form-item>
                        <a-upload style="display: inline-block;" :beforeUpload="segmentBeforeUpload" action="" @change="uploadClick">
                            <a-button class="blue-btn" type="primary">批量导入参与培训人员</a-button>
                        </a-upload>
                          <!-- <a-button class="blue-btn" type="primary" @click="uploadClick" >批量择参与培训人员</a-button> -->
                      </a-form-item>
                      <a-form-item>
                          <a-button class="blue-btn" type="primary" @click="batchCreate" >批量生成培训记录</a-button>
                      </a-form-item>
                      <a-form-item>
                          <a-button class="red-btn" type="primary" @click="batchDeletion" >批量删除</a-button>
                      </a-form-item>
                    </a-form>
                  </div>
                  <div style="margin-top: 15px;">
                        <commpVxeTable
                          :key="refreshTable"
                          :config="dataTableConfigRenYuan"
                          :formItem="formItemDjxq"
                          :columns="columnsVxe"
                          :scroll="{ x: 200 }"
                          @checkboxChange="checkboxChange"
                          ref="datatablePxry"
                          >
                          <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
                              <a-form layout="inline" class="search-form" >
                                  <a-form-item >
                                    <a-button class="blue-btn bth-mar-right" type="primary" @click="renyuandaJuanXiangQing(row)">试卷详情</a-button>
                                    <a-button class="blue-btn bth-mar-right" type="primary" @click="editPxryInfor(row)">编辑</a-button>
                                    <a-button class="red-btn" type="primary" @click="removePxry(row)">删除</a-button>
                                  </a-form-item>

                              </a-form>
                          </template>
                          <template v-slot:operation_khbtn="{row}" data-desc="考核操作栏">
                              <!-- <a-form layout="inline" class="search-form" > -->
                                  <!-- <a-form-item > -->
                                    <a-select v-model="row.fbz" placeholder="考核结果" style="width:100%;" @change="fkhjgChange(row)">
                                      <a-select-option v-if="row.fdf >= 60" value="合格">
                                        合格
                                      </a-select-option>
                                      <a-select-option v-else value="不合格">
                                        不合格
                                      </a-select-option>
                                    </a-select>
                                  <!-- </a-form-item> -->
                              <!-- </a-form> -->
                          </template>
                          <!-- <template v-slot:operation_smsbtn="{row}" data-desc="发送短信操作栏">
                            <span v-if="row.id">是</span>
                            <span v-else>否</span>
                          </template> -->
                        </commpVxeTable>
                        <a-modal
                          title="编辑"
                          :visible="editPxryInforVisible"
                          :confirm-loading="false"
                          @ok="handleOkPxry"
                          @cancel="editPxryInforVisible = false"
                        >
                          <a-form :form="editPxryForm">
                            <a-form-item label="电话号码">
                              <a-input v-model="editPxryForm.phone"></a-input>
                            </a-form-item>
                            <a-form-item label="电子邮箱">
                              <a-input v-model="editPxryForm.email"></a-input>
                            </a-form-item>
                            <a-form-item label="工作单位">
                              <a-input v-model="editPxryForm.address"></a-input>
                            </a-form-item>
                            <a-form-item label="是否参加本次培训">
                              <!-- <a-input v-model="editPxryForm.isJoin"></a-input> -->
                              <a-select v-model="editPxryForm.isJoin" placeholder="">
                                <a-select-option value="是">
                                  是
                                </a-select-option>
                                <a-select-option value="否">
                                  否
                                </a-select-option>
                              </a-select>
                            </a-form-item>
                            <a-form-item label="考核结果">
                              <a-select v-model="editPxryForm.fbz" placeholder="">
                                <a-select-option value="合格">
                                  合格
                                </a-select-option>
                                <a-select-option value="不合格">
                                  不合格
                                </a-select-option>
                              </a-select>
                            </a-form-item>
                          </a-form>
                        </a-modal>
                  </div>
                <selectRecipient ref="selectRecipientRef" @selectRecipientData="selectRecipientData" />
                </a-collapse-panel>
                <a-collapse-panel v-if="collapseShow" key="4" header="查看参加培训人员的答卷详情" :style="customStyle" class="collapse-panel-head-l380">
                  <commpVxeTable
                    :key="refreshTable4"
                    :config="dataTableConfigDjxq"
                    :columns="columnsVxeDjxq"
                    :scroll="{ x: 200 }"
                    @checkboxChange="checkboxChangeDjxq"
                    ref="datatableDjxq"
                    >
                    <template v-slot:operationDjxq_btn="{row}" data-desc="自定操作栏">
                      <a-form layout="inline" class="search-form" >
                          <a-form-item >
                              <a-button class="blue-btn bth-mar-right" type="primary" @click="daJuan(row)">答卷</a-button>
                              <a-button class="blue-btn" type="primary" @click="daJuanXiangQing(row)">查看</a-button>
                          </a-form-item>
                      </a-form>
                    </template>
                  </commpVxeTable>
                </a-collapse-panel>
                <a-collapse-panel v-if="collapseShow" key="5" header="人员培训记录" :style="customStyle">
                  <a-form layout="inline" style="display: flex;justify-content: flex-end;">
                      <a-form-item>
                          <a-button class="red-btn" type="primary" @click="batchDelUserPxjl" >批量删除</a-button>
                      </a-form-item>
                    </a-form>
                  <commpVxeTable
                    :key="refreshTable"
                    :config="dataTableConfigUserPxjl"
                    :columns="columnsVxeUserPxjl"
                    :scroll="{ x: 200 }"
                    @checkboxChange="checkboxChangeUserPxjl"
                    ref="datatableDjxq"
                    >
                    <template v-slot:operationPxjl_btn="{row}" data-desc="自定操作栏">
                      <a-form layout="inline" class="search-form" >
                          <a-form-item >
                              <a-button class="blue-btn" type="primary" @click="editUserPxjlFuntion(row)">编辑</a-button>
                          </a-form-item>
                      </a-form>
                    </template>
                  </commpVxeTable>
                  <a-modal
                    title="培训基本信息-编辑"
                    :footer="null"
                    :width="modalWidth"
                    :visible="userVisible"
                    :confirm-loading="confirmLoading"
                    @ok="submit"
                    @cancel="handleCancelUser"
                  >
                  <everdayFormNoRowAntcol
                      :key="inspectorKey"
                      :formItem="userForItem"
                      :beforeCreate="everdayUserform"
                      :labelcol="{ span: 8 }"
                    >
                    </everdayFormNoRowAntcol>
                    <a-form layout="inline" style="display: flex;justify-content: flex-end;">
                      <a-form-item>
                          <a-button class="blue-btn" type="primary" @click="handleCancelUser" >取消</a-button>
                      </a-form-item>
                      <a-form-item>
                          <a-button class="red-btn" type="primary" @click="saveUserTable" >保存</a-button>
                      </a-form-item>
                    </a-form>
                  </a-modal>
                </a-collapse-panel>
              </a-collapse>
            </div>
            <answerDetailed ref="refDetailed" :addEditParameter="addEditParameterDjxq" @refreshTableChange="refreshTableChange"/>
          </a-spin>
      </a-modal>
  </div>
</template>
<script>
import {typeSelect} from '@/components/compSearchCriteria/ContractType'
import everdayFormNoRowAntcol from "../../everydayCheck/components/everday-form-noRowAntcol.vue";
import compSearchCriteria from '@/components/compSearchCriteria/compSearchCriteria'
import {addServe, editServe,searchIdData,checkSjData,removeSjData,searchPxryData,addPxry,deletePxCjryArray,
        sendSjToPxCjry,sendSjSms,updateCjryXx,batchCreateMyPxjl,deleteBatchUserPxjl,editUserPxjl,
        downCjryTemplate,impPxCjryData,} from './service/index'
import compTable from '@/components/compTable/compTable'
import assessCheckApi from './service/api.js'
import selectRecipient from '../../../views/messageManagement/selectRecipient.vue'
import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue' // 新表格
import blobType from '@/common/blobType'
import {} from './service/index'
import answerDetailed from '../answerStatistics/answerDetailed.vue'
const trainingForItem = [
  {
    type: "input",
    label: "培训名称",
    model: "fpxmc",
    span: 8,
    labelCol: { span: 8 },
    rules:[{
        required: true,
        message: '请输入培训名称',
        trigger: 'blur',
    }],
  },
  {
    type: "comp-selector-type",
    dictType: "pxlx001",
    label: "培训类型",
    compType:'Select',
    defaultValue:'',
    model: "fpxlx",
    span: 8,
    labelCol: { span: 8 },
    rules: [{
      required: true,
      message: '请选择培训类型',
      trigger: 'blur',
    }]
  },
  {
    type: "input",
    label: "培训地点",
    model: "fpxdd",
    span: 8,
    labelCol: { span: 8 },
  },
  {
    type: "input",
    label: "主办科室",
    model: "fzzdw",
    span: 8,
    labelCol: { span: 8 },
  },
  // {
  //   type: "comp-selector-type",
  //   width:150,
  //   dictType: "pxdj001",
  //   label: "培训等级",
  //   defaultValue:'',
  //   compType:'Select',
  //   model: "fpxdj",
  //   span: 8,
  //   labelCol: { span: 8 },
  //   // slot: "xdyx001",
  // },
  // {
  //   type: "input",
  //   label: "培训主讲人",
  //   model: "fpxzjr",
  //   span: 8,
  //   labelCol: { span: 8 },
  // },
  // {
  //   type: "line",
  //   span: 24,
  // },

  {
    type: "line",
    span: 24,
  },
  //
  {
    type: "datetime",
    label: "开始时间",
    model: "fpxkssj",
    format: "YYYY-MM-DD",
    span: 8,
    labelCol: { span: 9 },
    // rules: [{
    //   required: true,
    //   message: '请选择培训开始时间',
    //   trigger: 'change',
    // }]
  },
  {
    type: "datetime",
    label: "结束时间",
    model: "fpxjssj",
    format: "YYYY-MM-DD",
    span: 8,
    labelCol: { span: 9 },
    // rules: [{
    //   required: true,
    //   message: '请选择培训结束时间',
    //   trigger: 'change',
    // }],
    // transform:function(value){ transformedValue:any}
  },

  {
    type: "comp-selector-type",
    width:150,
    dictType: "cjpxfs001",
    label: "参加方式",
    model: "fcjfs",
    compType:'Select',
    defaultValue:'',
    span: 8,
    labelCol: { span: 8 },
  },
  {
    type: "input",
    label: "培训学时",
    model: "fpxxs",
    span: 8,
    labelCol: { span: 8 },
  },

  {
    type: "line",
    span: 24,
  },
  //
  {
    type: "textarea",
    label: "培训内容",
    className:'form-item-box-witdh-l',
    model: "fpxnr",
    toHeight:true,
    style:{
      height:'200px',
    },
    span: 8,
    labelCol: { span: 8 },
  },
]
const userForItem = [
{
    type: "input",
    label: "培训名称",
    model: "fpxmc",
    span: 8,
    labelCol: { span: 8 },
    rules:[{
        required: true,
        message: '请输入培训名称',
        trigger: 'blur',
    }],
  },
  {
    type: "comp-selector-type",
    dictType: "pxlx001",
    label: "培训类型",
    compType:'Select',
    defaultValue:'',
    model: "fpxlx",
    span: 8,
    labelCol: { span: 8 },
    rules: [{
      required: true,
      message: '请选择培训类型',
      trigger: 'blur',
    }]
  },
  {
    type: "comp-selector-type",
    width:150,
    dictType: "pxdj001",
    label: "培训等级",
    compType:'Select',
    defaultValue:'',
    model: "fpxdj",
    span: 8,
    labelCol: { span: 8 },
    // slot: "xdyx001",
  },
  {
    type: "input",
    label: "培训主讲人",
    model: "fpxzjr",
    span: 8,
    labelCol: { span: 8 },
  },
  {
    type: "line",
    span: 24,
  },
  {
    type: "input",
    label: "培训地点",
    model: "fpxdd",
    span: 8,
    labelCol: { span: 8 },
  },
  {
    type: "input",
    label: "主办科室",
    model: "fzzdw",
    span: 8,
    labelCol: { span: 8 },
  },
  {
    type: "comp-selector-type",
    width:150,
    dictType: "cjpxfs001",
    label: "参加方式",
    model: "fcjfs",
    compType:'Select',
    defaultValue:'',
    span: 8,
    labelCol: { span: 8 },
  },
  {
    type: "line",
    span: 24,
  },
  //
  {
    type: "datetime",
    label: "开始时间",
    model: "fpxkssj",
    format: "YYYY-MM-DD",
    span: 8,
    labelCol: { span: 9 },
    // rules: [{
    //   required: true,
    //   message: '请选择培训开始时间',
    //   trigger: 'blur',
    // }]
  },
  {
    type: "datetime",
    label: "结束时间",
    model: "fpxjssj",
    format: "YYYY-MM-DD",
    span: 8,
    labelCol: { span: 9 },
    // rules: [{
    //   required: true,
    //   message: '请选择培训结束时间',
    //   trigger: 'blur',
    // }]
  },
  {
    type: "input",
    label: "培训学时",
    model: "fpxxs",
    span: 8,
    labelCol: { span: 8 },
  },
  {
    type: "input",
    label: "考核结果",
    model: "fkhjg",
    span: 8,
    labelCol: { span: 8 },
  },

  {
    type: "line",
    span: 24,
  },
  //
  {
    type: "textarea",
    label: "培训内容",
    className:'form-item-box-witdh-l',
    model: "fpxnr",
    toHeight:true,
    style:{
      height:'200px',
    },
    span: 24,
    labelCol: { span: 8 },
  },
]
export default {
  components:{
    everdayFormNoRowAntcol,
    compSearchCriteria,
    compTable,
    selectRecipient,
    commpVxeTable,
    answerDetailed
  },
  props:{
      addEditParameter:{
          type:Object,
          default:[]
      },
      fpxxx:{
          type:String,
          default:'',
          require:false
      }
  },
  data(){
      return{
          infoKey:null,
          modalWidth: '80%',
          inspectorKey:null,
          formData:{},
          userFormData:{},
          trainingForItem,
          userForItem,
          spinningKey:null,
          customStyle:"background: #f7f7f7;border-radius: 4px;margin-bottom: 10px;border: 0;overflow: hidden",
          spinning:true,
          form: this.$form.createForm(this, { name: 'coordinated' }),
          userForm: this.$form.createForm(this, { name: 'coordinatedUser' }),
          visibleShow:false,
          confirmLoading:false,
          typeSelect:typeSelect,
          formState:{},
          isAddATopic:false,//是否可以添加题目
          cuerrfpxxx:'',
          informationId: '',
          sjid: '',
          pxsjid: '', // 当前培训选择的试卷
          // 试卷弹窗
          compSelectorkey:'',
          visible: false,
          pxsjxxListKey: null,
          dataTableConfig:{
              api: assessCheckApi.searchSjData,
              rowKey: 'id',
              // rowName: 'fpxsj',
              rowSelection: {},
              fywflcode:'001002',
          },
          requestParams:{},
          pxSjRequestParams: {},
          formItem: [
            {
              label: '试卷名称',
              model: 'fsjmc'
            },
            {
              label: '试卷类型',
              model: 'fsjlx',
              type: typeSelect,
              dictionaryType: "培训类型",
              compType:'Select',
              defaultValue:'',
              currentValue:'',
            }
          ],
          formItemDjxq: [
            {
              label: '姓名',
              model: 'realname',
            },{
              label: '电话号码',
              model: 'flxdh'
            }
          ],
          columns: [
            {
              title: '试卷名称',
              dataIndex: 'fsjmc',
              key: 'fsjmc',
            },
            {
              title: '试卷类型',
              dataIndex: 'fsjlx',
              key: 'fsjlx',
            },
            {
              title: '创建时间',
              dataIndex: 'createTime',
              key: 'createTime'
            },
            {
              title: '操作',
              dataIndex: 'id',
              fixed: 'right',
              scopedSlots: {customRender: 'operation'},
              width:100,
            }
          ],
          // 参与培训人员弹窗
          refreshTable: null,
          refreshTable4: null,
          visibleMan: false,
          pxcyryListKey: null,
          selectedPxryRowKeysArr: [],
          // isSendTestPaper: false,
          dataTableConfigRenYuan:{
              api: assessCheckApi.searchPxryData,
              rowKey: 'id',
              rowSelection: {},
              paramet:{
                id: ''
              },
          },
          ryColumns: [
          {
              title: '姓名',
              dataIndex: '',
              key: '',
            },
            {
              title: '操作',
              dataIndex: 'id',
              fixed: 'right',
              scopedSlots: {customRender: 'pxryOperation'},
              width:100,
            }
          ],
          columnsVxe:[
            { type: 'checkbox', width: 60 ,fixed: 'left',},
            {
                title: '姓名', //列头显示文字
                field: 'realname',
                fixed: 'left',
            },{
                title: '工作单位',
                field: 'fgzdw',
            },{
                title: '职称',
                field: 'fzc',
            },{
                title: '电话',
                field: 'phone',
            },{
                title: '电子邮箱',
                field: 'email',
            },{
                title: '是否参加本次培训',
                field: 'fsfcjbcpx',
            },{
                title: '提交时间',
                field: 'ftjsj',
            },{
                title: '是否已发送短信',
                field: 'fdxfszt',
            },{
                title: '得分',
                field: 'fdf',
            },{
                title: '考核结果',
                field: 'id',
                slots: {
                // 使用插槽模板渲染
                default: 'operation_khbtn',
              },
            },
            // {
            //     title: '是否已发送短信',
            //     field: 'id',
            //     slots: {
            //     // 使用插槽模板渲染
            //     default: 'operation_smsbtn',
            //   },
            // },
            {
                title: '操作',
                field: 'id',
                slots: {
                // 使用插槽模板渲染
                default: 'operation_btn',
              },
                fixed: 'right',
                width:300,
            }
          ],
          fkhjgRenYuan: '',
          pxRyRequestParams: {},
          selectedArr: [],
          conditionData: {},
          editPxryInforVisible: false,
          editPxryForm: {
            id: '',
            address: '',
            email: '',
            phone: '',
            isJoin: undefined,
            fbz: '',
          },
          // 4
          dataTableConfigDjxq:{
              api: assessCheckApi.queryPxrySjxxPageList,
              rowKey: 'id',
              rowSelection: {},
              paramet:{
                fpxjbxxid: ''
              },
          },
          columnsVxeDjxq : [
            { type: 'checkbox', width: 60 ,fixed: 'left',},
            {
                title: '考生姓名', //列头显示文字
                field: 'fksxm',
                fixed: 'left',
            },{
                title: '试卷名称',
                field: 'fsjmc',
            },{
                title: '提交时间',
                field: 'ftjsj',
            },{
                title: '得分',
                field: 'fdf',
            },{
                title: '工作单位',
                field: 'fgzdw',
            },{
                title: '联系电话',
                field: 'flxdh',
            },{
                title: '操作',
                field: 'id',
                slots: {
                // 使用插槽模板渲染
                default: 'operationDjxq_btn',
              },
                fixed: 'right',
                width:200,
            }
          ],
          selectedDjxqRowKeysArr: [],
          addEditParameterDjxq: {},
          // 5
          dataTableConfigUserPxjl: {
            api: assessCheckApi.searchIdData,
            rowKey: 'id',
            listData: 'userPxjlList',
            paramet: {
              id: ''
            }
          },
          columnsVxeUserPxjl: [
            { type: 'checkbox',width: 60,fixed: 'left'},
            {
              title: '姓名',
              field: 'fusermc',
            },{
              title: '培训名称',
              field: 'fpxmc',
            },{
              title: '培训类型',
              field: 'fpxlx',
            },{
              title: '主办科室',
              field: 'fzzdw',
            },{
              title: '开始时间',
              field: 'fpxkssj',
            },{
              title: '结束时间',
              field: 'fpxjssj',
            },{
              title: '操作',
              field: 'id',
              slots: {
                default: 'operationPxjl_btn'
              },
              fixed: 'right',
              width: 100
            }
          ],
          selectedPxjlRowKeysArr: [],
          userVisible: false,
          collapseShow: false,
      }
  },
  watch:{
      addEditParameter(newval,oldVal){
        //console.log('newval',newval)
          this.assignment(newval)
      },
      fpxxx(newval,oldVal){
          //console.log('获取到试卷id了吗===========',newval)
          this.cuerrfpxxx = newval
      }
  },
  mounted(){
    if(this.$route.query.id){
            queryById({id:this.$route.query.id}).then(res=>{
                if(res.code == 200){
                    this.formState = res.result
                    this.selectedArr = res.result.fjsdx?res.result.fjsdx.split(','):[]
                    // this.columnsVxeUserPxjl = res.result.userPxjlList
                    this.fjsdxKey=Date.now()
                    this.newSMSKey=Date.now()
                }else{
                    this.$message.warning(res.message)
                }
            })
        }
  },
  updated(){
      // this.cancelLoading()
      // this.$refs.refTopicPage.getTopicPageData({isAddATopic:this.isAddATopic,cuerrfpxxx:this.cuerrfpxxx})
  },
  methods:{
      everdayform(form) {
        //console.log('当前的值',this.formData)
        this.form = form;
        this.form.setFieldsValue(
            this.lodash.pick(this.formData, Object.keys(this.formData))
          );
      },
      cancelLoading(){
          let timer = setInterval((val)=>{
              this.spinning = false
              clearInterval(timer);
          },500)

      },
      getData(val){
        //console.log('再次获取数据',val)
        this.cancelLoading()
          this.addEditParameter = val
          this.assignment(val)
          this.formData = val
          this.inspectorKey = Date.now()
          searchIdData({id:this.addEditParameter.id}).then(res => {
            if(res.code == 200){
              this.informationId = res.result.pxJbxx.id;
              this.dataTableConfigRenYuan.paramet.id = this.informationId
              this.dataTableConfigDjxq.paramet.fpxjbxxid = this.informationId
              this.dataTableConfigUserPxjl.paramet.id = this.informationId
              this.pxsjid = res.result.pxJbxx.fpxsjid;
              this.pxSjRequestParams = {id:this.pxsjid};
            }
          })
      },
      assignment(newval){
        //console.log(newval)
        if(newval.id){
          this.collapseShow = true
        } else {
          this.collapseShow = false
        }
        this.formData = {}
        this.formData = newval
        this.inspectorKey = Date.now()
      },
      //保存主表
      saveMainTable(e) {
          // e.preventDefault();
          var formState = {}
          this.form.validateFields((err, values) => {
              if (!err) {
                  // this.confirmLoading = true
                  formState = {
                      ...this.formState,
                      ...values
                  }
                  if(this.cuerrfpxxx){
                      formState.id = this.cuerrfpxxx
                  }
                  //console.log('formState.id',formState.id)
                  if(formState.id){
                      editServe(formState).then(res=>{
                          if(res.code == 200){
                              this.$message.success(res.message)
                              this.formState = formState
                              this.addEditParameter = formState
                              // this.visibleShow = false
                              this.$emit('handleOk',this.formState,1,1)
                              this.confirmLoading = false
                              this.isAddATopic = true
                              this.refreshClick()
                              this.assignment(this.formState)
                          }else{
                              this.$message.warning(res.message)
                              this.confirmLoading = false
                          }
                      }).catch(err =>{
                          this.confirmLoading = false
                      })
                  }else{
                    // //console.log('99',formState)
                    // //console.log('00',this.formState)
                    if(formState.fpxkssj == undefined || formState.fpxjssj == undefined){
                      this.$message.warning('请选择培训开始时间和培训结束时间')
                    } else {
                      addServe(formState).then(res=>{
                        //console.log(res)
                          if(res.code == 200){
                            
                              this.$message.success(res.message)
                              // this.visibleShow = false
                              this.addEditParameter = {id:res.result.id,...formState}
                              this.formState = {id:res.result.id,...formState}
                              // ---试卷---
                              this.pxsjid = res.result.fpxsjid;
                              this.pxSjRequestParams = {id:this.pxsjid};
                              // ----------
                              this.$emit('handleOk',this.formState,1)
                              this.cuerrfpxxx = res.result.id
                              // this.$refs.refTopicPage.currentRenovate()
                              this.confirmLoading = false
                              this.isAddATopic = true
                              this.refreshClick()
                              this.assignment(this.formState)
                              this.collapseShow = true
                          }else{
                              this.$message.warning(res.message)
                              this.confirmLoading = false
                          }
                      })
                      // .catch(err =>{
                      //     this.confirmLoading = false
                      // })
                    }
                  }

              }
          });
      },
      showModal() {
        this.visible = true;
      },
      selectRecipientClick(){
        this.$refs.selectRecipientRef.selectRecipientVisible = true
        this.$refs.selectRecipientRef.getData(this.selectedArr,this.conditionData)
      },
      submit(e) {
        this.confirmLoading = true;
        setTimeout(() => {
          this.visible = false;
          this.confirmLoading = false;
        }, 2000);
      },
      handleCancel(e) {
        this.visible = false;
      },
      returnClick(){
          this.visibleShow = false
          this.$emit('handleOk',{},true,1)
          // this.handleSubmit()
          this.addEditParameter.id = ''
          this.cuerrfpxxx = ''
      },
      refreshClick(){
        this.spinning = true
        this.infoKey = Date.now()
        this.cancelLoading()
          searchIdData({id:this.informationId}).then(res => {
            if(res.code == 200){
              this.pxsjid = res.result.pxJbxx.fpxsjid;
              this.pxSjRequestParams = {id:this.pxsjid};
            }
          })
      },
      //获取搜索数据
      searchHandleChange(val){
          if(val.resetEvents){
              this.compSelectorkey = Date.now()
          } else {
            this.dataTableConfig.requestParams =
            {...val}

          }
          this.requestParams = {...this.requestParams,...val,}
      },
      //获取选中表格rowKey
      selectedRowKeys(keys){
          this.selectedRowKeysArr = keys
      },
      //获取到排序的数据
      sorterChange(val,sorter){
          //console.log('获取到排序的数据',val,sorter)
      },
      // 选择试卷
      reviseClick(row){
        
        checkSjData({id:this.informationId,sjid:row[0].id}).then(res => {
          // //console.log(res)
          if(res.code == 200){
            this.$message.success(res.message);
            // this.visible = false;
            this.pxsjid = row[0].id
            this.pxSjRequestParams = {id:row[0].id};
            this.pxsjxxListKey = Date.now()
            // this.refreshClick(); // 刷新
          }
        })
      },

      // 移除试卷
      removeSj(row){
        removeSjData({id:this.informationId}).then(res => {
          if(res.code == 200){
            this.$message.success(res.message);
            this.refreshClick(); // 刷新
          }
        })
      },
      // 删除参加培训人员
      removePxry(row){
        deletePxCjryArray({ids:row.id}).then(res=>{
              if(res.code == 200){
                  this.$message.success(res.message)
              }else{
                  this.$message.warning(res.message)
              }
              this.refreshTable = Date.now()
          })
      },
      // 考核结果变动
      fkhjgChange(row){
        //console.log(row)
        let data = {}
        data = {
          fpxjbxxid: this.informationId,
          id: row.id,
          email: row.email,
          phone: row.phone,
          fgzdw: row.address,
          fsfcjbcpx: row.isJoin,
          fbz: row.fbz
        }
        updateCjryXx(data).then(res => {
          if(res.code == 200){
            this.$message.success(res.message)
            this.refreshTable = Date.now()
          } else {
            // this.$message.warning(res.message)
          }
        })
      },
      // 编辑参与培训人员信息
      editPxryInfor(val){
        this.editPxryInforVisible = true
        this.editPxryForm.id = val.id
        this.editPxryForm.email = val.email
        this.editPxryForm.phone = val.phone
        this.editPxryForm.address = val.fgzdw
        this.editPxryForm.isJoin = val.fsfcjbcpx
        this.editPxryForm.fbz = val.fbz
      },
      handleOkPxry(){
        let data = {}
        data = {
          fpxjbxxid: this.informationId,
          id: this.editPxryForm.id,
          email: this.editPxryForm.email,
          phone: this.editPxryForm.phone,
          fgzdw: this.editPxryForm.address,
          fsfcjbcpx: this.editPxryForm.isJoin,
          fbz: this.editPxryForm.fbz
        }
        updateCjryXx(data).then(res => {
          if(res.code == 200){
            this.$message.success(res.message)
            this.refreshTable = Date.now()
          } else {
            this.$message.warning(res.message)
          }
          this.editPxryInforVisible = false
        })
      },
      checkboxChange(val){//获取当前选择的行
            //console.log('当前选择表格',val)
            this.selectedPxryRowKeysArr = []
            val.forEach(item => {
                this.selectedPxryRowKeysArr.push(item.id)
            });
        },
        selectRecipientData(val,conditionData){//选择后的接收对象
          // val:已选id+name
          // conditionData：部门
          let arr = []
          if(val.length){
            val.forEach(item => {
              arr.push(item.id)
            })
          }
          let arrString = ''
          arrString = arr.toString()
          addPxry({id:this.informationId,fuserids:arrString}).then(res => {
            // //console.log(res)
            if(res.code == 200){
              this.$message.success(res.message);
              searchPxryData({id:this.informationId}).then(res => {
                // this.$refs.datatablePxry.searchEvent()
                this.refreshTable = Date.now()
              })
            } else {
              this.$message.warning(res.message);
            }
          })
        },
        // 批量删除
        batchDeletion(){
          var that = this
          this.$confirm({
              title:'您确认要删除吗？',
              onOk() {
                  if(that.selectedPxryRowKeysArr.length){
                      let deleteString = that.selectedPxryRowKeysArr.join(',')
                      let add = deleteString.toString()
                      deletePxCjryArray({ids:add}).then(res=>{
                        // //console.log('删除',res)
                          if(res.code == 200){
                              that.$message.success(res.message)
                              that.refreshTable = Date.now()
                          }else{
                              that.$message.warning(res.message)
                          }
                      })
                  }else{
                      that.$message.warning(res.message)
                  }
              },
          });
        },
        // 下载模板
        downTemplate(val){
          var that = this
          var fileName = '培训参加人员-导入模板'
          downCjryTemplate().then((data) => {
             // //console.log(data)
            if (!data) {
                that.$message.warning('文件下载失败')
                return
            }
            let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', fileName + '.xls')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link) //下载完成移除元素
            window.URL.revokeObjectURL(url) //释放掉blob对象
            that.$message.success(res.message)
          })
        },
        // 上传原本接口取消
        segmentBeforeUpload(e){
          return false
        },
        // 导入培训人员模板
        uploadClick({file}){
          var that = this
          if(typeof file.uid !== 'undefined') {
            const fileData = new FormData();
            fileData.append("file",file);
            fileData.append("fpxjbxxid",this.informationId);
            impPxCjryData(fileData).then(res => {
              // //console.log('fileData',res)
                if(res.code == 200){
                  that.$message.success(res.message)

                  this.refreshTable = Date.now()
                }else{
                  that.$message.warning(res.message)
                }
            })
          }
        },
        // 批量生成培训记录
        batchCreate(){
          var that = this
          this.$confirm({
              title:'您确认要批量生成培训记录吗？',
              onOk() {
                  if(that.selectedPxryRowKeysArr.length){
                      let deleteString = that.selectedPxryRowKeysArr.join(',')
                      let add = deleteString.toString()
                      batchCreateMyPxjl({ids:add}).then(res=>{
                        //console.log('培训记录',res)
                          if(res.code == 200){
                              that.$message.success(res.message)
                              that.refreshTable = Date.now()
                              this.getUserPxjl()
                          }else{
                              that.$message.warning(res.message)
                          }
                      })
                      that.refreshTable = Date.now()
                  }else{
                      that.$message.warning('请选择生成项')
                  }
              },
          });
        },
        // 发送试卷
        sendTestPapers(){
          // //console.log(this.isSendTestPaper)
          sendSjToPxCjry({id:this.informationId}).then(res => {
            if(res.code == 200){
              this.$message.success(res.message)

              // this.isSendTestPaper = true
              // queryPxrySjxxPageList({fpxjbxxid:this.informationId}).then(res => {
              // })
              this.dataTableConfigDjxq.paramet.fpxjbxxid = this.informationId
                this.refreshTable = Date.now()
              // this.dataTableConfigDjxq
            } else {
              this.$message.warning(res.message)
            }
          })
        },
        // 发送试卷短信
        sendSms(){
          var that = this
          //console.log(that.selectedPxryRowKeysArr.length)
          if(that.selectedPxryRowKeysArr.length == 0){
            that.$message.warning('请选择勾选项')
          } else {
            that.$confirm({
              title: '您确认要已勾选人发送试卷吗？?',
              content: '',
              okText: '确实',
              okType: 'danger',
              cancelText: '取消',
              onOk() {
                //console.log(that.selectedPxryRowKeysArr)
                //console.log(that.selectedPxryRowKeysArr.toString())
                sendSjSms({id:that.informationId,ids:that.selectedPxryRowKeysArr.toString()}).then(res => {
                  //console.log(res)
                  if(res.code == 200){
                    that.$message.success(res.message)
                    that.refreshTable = Date.now()
                    that.refreshTable4 = Date.now()
                  } else {
                    that.$message.warning(res.message)
                  }
                })
              },
              onCancel() {
                //console.log('取消');
              },
            });
          }
        },
        // 4
        // 勾选数据id数组
        checkboxChangeDjxq(val){
          this.selectedDjxqRowKeysArr = []
            val.forEach(item => {
                this.selectedDjxqRowKeysArr.push(item.id)
            });
        },
        //答卷
        daJuan(row){
          var a = document.createElement('a');
          a.href = bootConfig[process.env.NODE_ENV].EXTERNAL_ACCESS_URL+process.env.BASE_URL+'examinationPaper?id='+row.id
          a.click();
        },
        //
        renyuandaJuanXiangQing(val){
          // //console.log(val)
          let data = {}
          data = {
            id: val.djid
          }
            this.addEditParameterDjxq = {}
            this.$refs.refDetailed.visibleDetailedShow = true
            this.$refs.refDetailed.getData(data)
            this.addEditParameterDjxq = val

            // queryPxrySjxxPageList({djid: val.djid}).then(res => {
            //   //console.log(res)
            // })
        },
        refreshTableChange(){
          this.refreshTable = Date.now()
        },
        // 答卷详情
        daJuanXiangQing(val){//详情
            this.addEditParameterDjxq = {}
            this.$refs.refDetailed.visibleDetailedShow = true
            this.$refs.refDetailed.getData(val)
            this.addEditParameterDjxq = val
        },
        // 5
        getUserPxjl(){
          this.dataTableConfigUserPxjl.paramet.id = this.informationId
          this.refreshTable = Date.now()
        },
        // 勾选
        checkboxChangeUserPxjl(val){
          this.selectedPxjlRowKeysArr = []
            val.forEach(item => {
                this.selectedPxjlRowKeysArr.push(item.id)
            });
        },
        // 批量删除培训记录
        batchDelUserPxjl(){
          var that = this
          this.$confirm({
              title:'您确认要删除吗？',
              onOk() {
                  if(that.selectedPxjlRowKeysArr.length){
                      let deleteString = that.selectedPxjlRowKeysArr.join(',')
                      let add = deleteString.toString()
                      deleteBatchUserPxjl({ids:add}).then(res=>{
                        //console.log(res)
                          if(res.code == 200){
                              that.$message.success(res.message)
                              that.refreshTable = Date.now()
                          }else{
                              that.$message.warning(res.message)
                          }
                      })
                  }else{
                      that.$message.warning('请选择删除项')
                  }
              },
          });
          // deleteBatchUserPxjl().then(res => {})
        },
        handleCancelUser(){
          //console.log('关闭')
          this.userVisible = false
        },
        // 保存方法
        saveUserTable(){
          //console.log('保存')
          var formState = {}
          this.userForm.validateFields((err, values) => {
            //console.log('values',values)
              if (!err) {
                  this.confirmLoading = true
                  formState = {
                      ...this.formState,
                      ...values
                  }
                  // //console.log(this.userForm)
                  // //console.log(this.userFormData)
                  let data = {}
                  let val = values
                  data = {
                    id: this.userFormData.id,
                    fpxmc: val.fpxmc,
                    fpxlx: val.fpxlx,
                    fpxdj: val.fpxdj,
                    fpxzjr: val.fpxzjr,
                    fpxdd: val.fpxdd,
                    fzzdw: val.fzzdw,
                    fcjfs: val.fcjfs,
                    fpxkssj: val.fpxkssj,
                    fpxjssj: val.fpxjssj,
                    fpxxs: val.fpxxs,
                    fkhjg: val.fkhjg,
                    fpxnr: val.fpxnr,
                  }
                    editUserPxjl(data).then(res=>{
                      //console.log(res)
                          if(res.code == 200){
                              this.userVisible = false
                              this.$message.success(res.message)
                              this.refreshTable = Date.now()
                              this.$emit('handleOk',formState,1,1)
                              this.confirmLoading = false
                          }else{
                              this.$message.warning(res.message)
                              this.confirmLoading = false
                          }
                      }).catch(err =>{
                          this.confirmLoading = false
                      })
              }
          });
        },
        // 用户培训记录-编辑点击
        editUserPxjlFuntion(row){
          this.userVisible = true
          this.userFormData = row
        this.inspectorKey = Date.now()

          // editUserPxjl().then(res => {})
        },
        everdayUserform(form) {
          //console.log('form',form)
          this.userForm = form;
          this.userForm.setFieldsValue(
              this.lodash.pick(this.userFormData, Object.keys(this.userFormData))
            );
            //console.log('userFormData',this.userFormData)
        },

  }

}

</script>
<style lang="less">
/* .ant-form-item-label{
  font-weight: 600;
} */

.ant-modal-title{
  font-weight: 600;
}
.ant-modal-header{
  background: #5ca3e5;
}
.ant-upload-list{
  display: none !important;
}
.ant-modal-footer .ant-btn-primary{
  border: 1px solid #5ca3e5 !important;
  background-color: #5ca3e5 !important;
  color: #fff !important;
}
.test-paper-modal .ant-modal-header{
  display: none !important;
}
.test-paper-modal .ant-modal-footer{
  display: none !important;
}
.test-paper-modal .ant-modal-content{
  height: 100vh;
  overflow: auto;
}
.full-modal {
  .ant-modal {
    max-width: 100%;
    top: 0;
    padding-bottom: 0;
    margin: 0;
  }
  .ant-modal-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    height: calc(100vh);
  }
  .ant-modal-body {
    flex: 1;
  }
}
.bth-mar-right {
  margin-right: 10px;
}
.red-btn{
    border: 1px solid #ed5565 !important;
    background-color: #ed5565 !important;
}
.ant-row .ant-form-item .form-textarea {
  width: 500px !important;
}
</style>
